<?php
class Member extends CS_Controller
{
    
    function _init(){
        $this->load->helper(array('common'));
        $this->load->library('pagination');
        $this->load->model('user_model', 'user');
    }
    
    function index($pg = 1){
        $num = ($pg-1)*20;
        $config['base_url'] = base_url('member/index');
        $config['total_rows'] = $this->user->userRegParentTotal(array());
        $config['uri_segment'] = 3;
        $this->pagination->initialize($config);
        $data['pg_link'] = $this->pagination->create_links();
        $data['userObj'] = $this->user->findByRegs($num);
        $data['all_rows'] = $config['total_rows'];
        $data['pg_now'] = $pg;
        $this->load->view('member/index', $data);
    }
    
    
    public function search($pg = 1)
    {
        if (!$this->search_get_validate($this->input->get())) {
            $this->redirect('member/index');
        }
        $data['startDate'] = $this->input->get('startDate');
        $data['endDate']   = $this->input->get('endDate');
        
        if($this->input->get('userName')){
            $result = $this->user->findByIds(array('user_name'=>array($this->input->get('userName'))));
            if($result->num_rows() == 1){
                $data['parent_id'] = $result->row()->uid;
            }
        }
        $getData = $data;
        $data['userName']  = $this->input->get('userName');
    
        $num = ($pg-1)*20;
        $config['first_url'] = base_url('member/search').$this->pageGetParam($this->input->get());
        $config['suffix'] = $this->pageGetParam($this->input->get());
        $config['base_url']    = base_url('member/search');
        $config['total_rows']  = $this->user->userRegParentTotal($getData);
        $config['uri_segment'] = 3;
        $this->pagination->initialize($config);
        $data['pg_link']   = $this->pagination->create_links();
        $data['userObj'] = $this->user->findByRegs($num, $getData);
        $data['all_rows']  = $config['total_rows'];
        $data['pg_now']    = $pg;
        $this->load->view('member/index', $data);
    }
    
    function detail($pg = 1){
        $getData = $this->input->get();
        $num = ($pg-1)*20;
        $config['first_url'] = base_url('member/detailSearch').$this->pageGetParam($this->input->get());
        $config['suffix'] = $this->pageGetParam($this->input->get());
        $config['base_url'] = base_url('member/detail');
        $config['total_rows'] = $this->user->userRegTotal($getData);
        $config['uri_segment'] = 3;
        $this->pagination->initialize($config);
        $data['pg_link'] = $this->pagination->create_links();
        $data['userObj'] = $this->user->findBydetails($num,$getData);
        $data['all_rows'] = $config['total_rows'];
        $data['pg_now'] = $pg;
        $this->load->view('member/detail', $data);
    }
    
    
    public function detailSearch($pg = 1)
    {
        if (!$this->search_get_validate($this->input->get())) {
            $this->redirect('member/detail');
        }
        $data['startDate'] = $this->input->get('startDate');
        $data['endDate']   = $this->input->get('endDate');
    
        if($this->input->get('userName')){
            $result = $this->user->findByIds(array('user_name'=>array($this->input->get('userName'))));
            if($result->num_rows() == 1){
                $data['parent_id'] = $result->row()->uid;
            }
        }
        $getData = $data;
        $data['userName']  = $this->input->get('userName');
    
        $num = ($pg-1)*20;
        $config['first_url'] = base_url('member/detailSearch').$this->pageGetParam($this->input->get());
        $config['suffix'] = $this->pageGetParam($this->input->get());
        $config['base_url']    = base_url('member/detailSearch');
        $config['total_rows']  = $this->user->userRegParentTotal($getData);
        $config['uri_segment'] = 3;
        $this->pagination->initialize($config);
        $data['pg_link']   = $this->pagination->create_links();
        $data['userObj'] = $this->user->findBydetails($num, $getData);
        $data['all_rows']  = $config['total_rows'];
        $data['pg_now']    = $pg;
        $this->load->view('member/detail', $data);
    }
    
}